package com.ming.springboot.security;

import com.alibaba.fastjson.JSON;
import com.ming.springboot.data.Result;
import com.ming.springboot.data.ResultCode;
import org.springframework.security.core.AuthenticationException;
import org.springframework.security.web.AuthenticationEntryPoint;
import org.springframework.stereotype.Component;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * Created by mqsi on 2022/5/24 15:49
 */
@Component
public class AjaxAuthenticationEntryPoint implements AuthenticationEntryPoint {
	@Override
	public void commence(HttpServletRequest request, HttpServletResponse response, AuthenticationException authException) throws IOException, ServletException {
		Result result = Result.fail(ResultCode.NEED_LOGIN.getCode(), "Need Login");
		response.getWriter().write(JSON.toJSONString(result));
	}
}
